<template>
  <div>
    <!-- <p class="pinformation">样品信息</p>
    <el-form :model="form" label-width="120">
      <el-row>
        <el-form-item label="样品编号总数：">
          {{ form.sampleCodeCount }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="已交接样品总数：">
          {{ form.withSampleCount }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="未交接样品总数：">
          {{ form.notWithSampleCount }}
        </el-form-item>
        <el-form-item style="margin-left: 10px" label="已交接批次总数：">
          {{ form.withCount }}
        </el-form-item>
      </el-row>
    </el-form> -->
    <p class="pinformation">样品交接表搜索</p>
    <el-form ref="queryRef" label-width="80" :model="queryParams">
      <el-row>
        <el-col :span="3">
          <el-form-item :label="cyOrSylabel + '人员：'" prop="cyUserName" label-width="80">
            <el-input @keyup.enter="handleQuery" clearable maxlength="100" placeholder="请输入"
              v-model="queryParams.cyUserName" />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="采样时间：" label-width="80">
            <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-form-item label="收样人：" prop="getUserName" label-width="80">
            <el-input @keyup.enter="handleQuery" clearable maxlength="100" placeholder="请输入"
              v-model="queryParams.getUserName" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="收样时间：" prop="getDate" label-width="80">
            <el-date-picker v-model="queryParams.getDate" value-format="YYYY-MM-DD" :clearable="false" :editable="false"
              :picker-options="false" placeholder="收样时间"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-row style="justify-content: center">
            <el-button type="success" @click="handleQuery">搜索</el-button>
            <el-button class="resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <p class="pinformation">样品交接表列表</p>
      <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table border :data="tableData" ref="dataTableRef" v-loading="loading">
      <el-table-column align="center" show-overflow-tooltip label="批次序号" prop="withNumber" width="85" />
      <el-table-column align="center" show-overflow-tooltip :label="cyOrSylabel + '人员'" prop="cyUserName" />
      <el-table-column align="center" show-overflow-tooltip label="采样时间" prop="sampleDate" width="300">
        <template #default="scope">
          {{ scope.row.cyStartDate }} {{ scope.row.cyStartDate ? "-" : "" }} {{ scope.row.cyEndDate }}
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip label="收样人" prop="getUserName" width="100" />
      <el-table-column align="center" show-overflow-tooltip label="收样时间" prop="getDate" width="100" />
      <el-table-column align="center" show-overflow-tooltip label="样品数量" prop="sampleCount" width="100" />
      <el-table-column show-overflow-tooltip label="操作" align="center" width="70" fixed="right">
        <template #default="scope">
          <el-button link type="success" @click="handleView(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
    <el-dialog :class="'el-dialog-theme3'" v-model="show" fullscreen title="查看样品交接详情">
      <record :isHide="true" ref="recordRef"></record>
    </el-dialog>
  </div>
</template>

<script setup>
import { getYpjjFrom, getYpjjList, isSyProject } from "@/api/taskProgressDetails/index";
import { nextTick } from "vue";
import record from "../../../flowable/task/record/index.vue";
const { proxy } = getCurrentInstance();
const tableData = ref([]);
const total = ref(0);
const queryParams = ref({ pageNum: 1, pageSize: 10 });
const form = ref({});
const loading = ref(false)
const dateRange = ref([]);
const projectId = ref("");
const show = ref(false)
const recordRef = ref(null)
const cyOrSylabel = ref("采样");
function getForm(val) {
  projectId.value = val;
  getCyOrCyLabel();
  queryParams.value.projectId = val;
  getYpjjFrom(projectId.value).then((res) => {
    form.value = res.data;
  });
  getList();
}

function getCyOrCyLabel(){
  //查询当前方案是采样还是送样，用于改变采样或送样的文字显示。
  isSyProject(projectId.value).then(res => {
    if(res.data && res.data == 2){
      cyOrSylabel.value = "送样";
    }
  })
}

function getList() {
  loading.value = true
  getYpjjList(proxy.addDateRange(queryParams.value, dateRange.value)).then(
    (res) => {
      tableData.value = res.rows;
      total.value = res.total;
      loading.value = false
    }
  );
}

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy.resetForm("queryRef");
  dateRange.value = [];
  handleQuery();
}

function handleView(row) {
  show.value = true
  nextTick(() => {
    recordRef.value.getInfo(row.procInsId)
  })
}


defineExpose({
  getForm,
});

const heightParams = ref([{ tableName: "data", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}

onMounted(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});

onUpdated(() => {
  nextTick(function () {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "data", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "data", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);
</script>

<style></style>
